package com.whcoding.redis.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.whcoding.redis.common.RedisTemplateUtil;
import com.whcoding.redis.pojo.OrmDeptVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @author: whcoding
 * @create: 2022-02-23 14:29
 */
@RestController
public class RedisController {


	@Autowired
	@Qualifier("redisTemplate")
	private RedisTemplate redisTemplate;


	@GetMapping("/redisTest")
	public ResponseEntity redisTest() throws JsonProcessingException {
		OrmDeptVO deptVO = new OrmDeptVO();
		deptVO.setId(Long.valueOf("1"));
		deptVO.setDeptId(1001);
		deptVO.setDeptNo("CG_001");
		deptVO.setDeptType(3);
		deptVO.setDeptName("采购部");
		deptVO.setCreateTime(new Date());
		deptVO.setUpdateTime(new Date());
		deptVO.setDeptPerf(BigDecimal.ONE);
		deptVO.setIsValidFlag(1);
		deptVO.setShortName("CG");
		deptVO.setRemark("AAA");

		String jsonSrt = new ObjectMapper().writeValueAsString(deptVO);
		redisTemplate.opsForValue().set("dept", jsonSrt);
		return ResponseEntity.ok().build();
	}
}
